# 二叉树展开为链表
# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def flatten(self, root: TreeNode) -> None:
        """
        Do not return anything, modify root in-place instead.
        """
        if root is None:
            return
        right = root.right
        left = root.left
        root.right = None
        root.left = None
        if left is not None:
            self.flatten(left)
            root.right = left
        if right is not None:
            self.flatten(right)
            tmp = root
            while tmp.right is not None:
                tmp = tmp.right
            tmp.right = right


if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    root.left.right = TreeNode(-5)
    root.right = TreeNode(10)
    r = so.flatten(root)
    print(so)
